//
//  MKSettingViewController.swift
//  MOKOAnnounce
//
//  Created by _SS on 2017/7/13.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  设置页面

import UIKit

class MKSettingViewController: MKBaseViewController,UITableViewDelegate,UITableViewDataSource {

    var titles:NSArray!
    var listView:UITableView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        titles = [["账号与安全"],["新消息通知","关于美空通告","联系我们"]]
        makeUI()
        // Do any additional setup after loading the view.
    }
    
    func makeUI() -> Void {
        titleBar = MKTitleBar().titleBar(title: "设置", leftStyle: .Back, rightStyle: .None, barStyle: .Default)
        titleBar?.delegate = self
        self.view .addSubview(titleBar!)
        
        listView = UITableView.init(frame:CGRect.init(x: 0, y: (titleBar?.bottom)!, width: ScreenWidth, height: ScreenHeight - 64) , style: .grouped)
        listView.delegate = self
        listView.dataSource = self
        self.view.addSubview(listView)
        
        
        let view:UIView = UIView.init(frame: CGRect.init(x: 0, y:0, width: ScreenWidth, height: 44.0))
        view.backgroundColor = UIColor.white
        let button:UIButton = UIButton.init(type: .custom)
        button.frame = CGRect.init(x: 0, y: 0, width: ScreenWidth, height: 44.0)
        button.setTitle("退出登录", for: .normal)
        button.backgroundColor = UIColor.white
        button.setTitleColor(UIColor.black, for: .normal)
        button.addTarget(self, action:#selector(logout) , for: .touchDown)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16.0)
        view.addSubview(button)
        listView.tableFooterView = view
        
    }
    
    func logout() -> Void {
        let alertController = UIAlertController.init(title: nil, message: "确认退出？", preferredStyle: .alert)
        let cancel = UIAlertAction.init(title: "取消", style: .cancel) { (UIAlertAction) in
            print("取消退出")
        }
        alertController.addAction(cancel)
        
        let sure = UIAlertAction.init(title: "确认", style: .default) { (UIAlertAction) in
            print("确认退出")
        }
        alertController.addAction(sure)
        self.present(alertController, animated: true, completion: nil)
    }

    func titleBarLeftClick() {
        self.navigationController?.popViewController(animated: true)
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let array:NSArray = titles.object(at: indexPath.section) as! NSArray
        print(array.object(at: indexPath.row))
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return titles.count
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 1{
            return 10.0
        }
        return 5.0;
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 1{
            return 10.0
        }
        return 0.1;
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let array:NSArray = titles.object(at: section) as! NSArray
        return array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifer:NSString = "settingCellIdentifier"
        var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifer as String)
        if (cell == nil) {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: cellIdentifer as String)
            cell?.textLabel?.font = UIFont.systemFont(ofSize: 16.0)
            cell?.accessoryType = .disclosureIndicator
            cell?.selectionStyle = .none
        }
        let array:NSArray = titles.object(at: indexPath.section) as! NSArray
        cell?.textLabel?.text = array.object(at: indexPath.row) as? String
        return cell!
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
